# -*- coding: utf-8 -*-
# @Time : 2021/2/3 17:30
# @Author : shx
# @Email : 925126486@qq.com
# @File : template_set_page.py
# @Project : test
from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from selenium import webdriver


class SetPage(BasePage):
    """定义模板设置页面"""
    url_ = 'http://192.168.1.49/crm3/index.php?m=sms&a=index'
    add_locator = (By.ID, 'add')
    biaoti_locator = (By.TAG_NAME, 'input[name=subject]')
    contin_locator = (By.ID, 'content')
    baocun_locator = (By.TAG_NAME, 'input[name=submit]')
    tbody_locator = (By.CSS_SELECTOR, '#form1 > div:nth-child(2) > table > tbody')
    tr_locator = (By.TAG_NAME,'tr')
    td_locator = (By.TAG_NAME,'td')
    td_a_locator = (By.CSS_SELECTOR,'tbody > tr:nth-child(1) > td:nth-child(1) > input')
    del_locator = (By.ID,'btn_delete')

    def get_current_url(self):
        return self.driver.current_url

    def add_sms_set(self):
        """进入短信设置页面"""
        self.find_element(self.add_locator).click()

    def input_title(self,contant):
        """输入短信设置模板标题"""
        self.find_element(self.biaoti_locator).send_keys(contant)

    def input_contant(self,neirong):
        """输入短信设置模板内容"""
        self.find_element(self.contin_locator).send_keys(neirong)

    def point_sure(self):
        """短信模板设置中点击确定"""
        self.find_element(self.baocun_locator).click()

    def tbody_element(self):
        return self.find_element(self.tbody_locator)

    def select_template(self,text,check):
        """选中新添加的模板"""
        tbody_element = self.find_element(self.tbody_locator)
        trs = tbody_element.find_elements(*self.tr_locator)
        for i in range(len(trs)):
            title = trs[i].find_element(By.CSS_SELECTOR,f'tr>td:nth-child({check})').text
            if text == title:
                trs[i].find_element(By.CSS_SELECTOR,'tr>td:nth-child(1)>input').click()
                break

    def point_del(self):
        """点击删除"""
        self.find_element(self.del_locator).click()


